﻿using Core.Manager;
using Core.UI;
using Core.UI.UISub;
using Core.UI.UISub.ModalWindow;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

namespace Game.UI.Example
{
    public class WeaponPanel : UIPanelBase
    {
        public Button goHomeBtn;
        public Button changeWeaponBtn;
        public Button startGameBtn;
        public Button backBtn;

        protected override void Awake()
        {
            base.Awake();
            
            goHomeBtn.onClick.AddListener(OnClickGoHome);
            changeWeaponBtn.onClick.AddListener(OnClickChangeWeapon);
            startGameBtn.onClick.AddListener(OnClickToGame);
            backBtn.onClick.AddListener(OnClickBack);
        }

        private void OnClickToGame()
        {
            GameSceneManager.Ins.LoadScene("ui_2").Forget();
        }

        private void OnClickGoHome()
        {
            UIManager.Ins.ShowUI(UIPanelName.MenuPanel).Forget();
        }

        private void OnClickBack()
        {
            this.HideSelf();
        }

        private async void OnClickChangeWeapon()
        {
            var tipsUI = await UIManager.Ins.ShowUI(UIPopupWinName.TipsWindow, ui =>
            {
                UITipsPopupWindow tipsPopupWindow = (UITipsPopupWindow)ui;
                tipsPopupWindow.SetTips("Are you sure you want to change weapons ?", "Revert to default weapon"
                    , "Change Weapon");
            });
            tipsUI.OptionalCallback(choice =>
            {
                if (choice == 1)
                    Debug.Log("成功更换武器");
                else if (choice == 2)
                    Debug.Log("取消更换武器");
                else
                    Debug.Log("恢复为默认武器");
            });
        }
    }
}